package com.example.demo.service.impl;

import com.example.demo.dao.Address;
import com.example.demo.dao.AddressExample;
import com.example.demo.mapper.AddressMapper;
import com.example.demo.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public  class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressMapper addressMapper;
    //通过userid查找
    @Override
    public Address findAddressByuserId(Integer userid) {
        AddressExample addressExample = new AddressExample();
        AddressExample.Criteria criteria = addressExample.createCriteria();
        criteria.andUseridEqualTo(userid);
        List<Address> addresses =addressMapper.selectByExample(addressExample);
         Address address=null;
        if(addresses!=null){
           address= addresses.get(0);
        }
        return address;
    }

    @Override
    public List<Address> findaddById(Integer id) {
        return addressMapper.findaddById(id);
    }

    @Override
    public Address findAddressByAddressid(Integer id) {
        return addressMapper.selectByPrimaryKey(id);
    }
    //通过主键删除地址
    @Override
    public void deladdByAddressid(Integer id) {
        addressMapper.deleteByPrimaryKey(id);
    }
    //添加地址
    @Override
    public void insert(Address address){
        addressMapper.insert(address);
    }
    //寻找最大id
    @Override
    public int findMaxAddressid() {
        return addressMapper.findMaxId();
    }
}
